package com.github.live.adapter;

import android.annotation.SuppressLint;
import android.graphics.Color;
import android.widget.TextView;

import com.github.live.R;
import com.github.livebase.util.base.DateUtil;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @ClassName EpgHeaderAdapter
 * @description: epg回看界面头部，日期
 * @author: biao532
 * @create: 2024-01-03 16:56
 * @Version 1.0
 **/
public class EpgHeaderAdapter extends SimpleRecyclerAdapter<Date>{
    private static SimpleDateFormat format = new SimpleDateFormat("MM-dd");
    private int selectedChannelIndex = -1;
    private int activeChannelIndex = -1;

    @SuppressLint("ResourceType")
    public EpgHeaderAdapter() {
        super(R.layout.item_replay_epg_header);
    }

    @Override
    void onBindViewHolder(SimpleViewHolder holder, Date data, int position) {
        TextView d = holder.findViewById(R.id.epg_date);
        TextView dw = holder.findViewById(R.id.epg_date_week);
        String[] week = mContext.getResources().getStringArray(R.array.week_name);
        d.setText(DateUtil.format(format, data));
        dw.setText(week[data.getDay()]);
        if (position == selectedChannelIndex) {
            d.setTextColor(mContext.getResources().getColor(R.color.color_theme));
            dw.setTextColor(mContext.getResources().getColor(R.color.color_theme));
        }
        else{
            d.setTextColor(Color.WHITE);
            dw.setTextColor(Color.WHITE);
        }
    }


    public void setSelectedChannelIndex(int selectedChannelIndex) {
        if (selectedChannelIndex == this.selectedChannelIndex) return;
        int preSelectedChannelIndex = this.selectedChannelIndex;
        this.selectedChannelIndex = selectedChannelIndex;
        if (preSelectedChannelIndex != -1)
            notifyItemChanged(preSelectedChannelIndex);
        if (this.selectedChannelIndex != -1)
            notifyItemChanged(this.selectedChannelIndex);
        else if (this.activeChannelIndex != -1)
            notifyItemChanged(this.activeChannelIndex);
    }

    public void setActiveChannelIndex(int activeChannelIndex) {
        if (this.activeChannelIndex == activeChannelIndex) return;
        this.activeChannelIndex = activeChannelIndex;
    }

    public int getSelectedChannelIndex() {
        return selectedChannelIndex;
    }

    public int getActiveChannelIndex() {
        return activeChannelIndex;
    }
}
